
$(function() {
	var grid;
	var columns = [{
	    id: "#",
	    name: "",
	    width: 40,
	    behavior: "selectAndMove",
	    unselectable: true,
	    resizable: false,
	    cssClass: "cell-reorder"
	}, {
	    id: "date",
	    name: "日期",
	    field: "date",
	    width: 100,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Date,
	    validator: requiredFieldValidator
	}, {
	    id: "content",
	    name: "内容",
	    field: "content",
	    width: 400,
	    cssClass: "cell-title",
	    editor: LongSlick.Editors.Text,
	    validator: requiredFieldValidator
	}, {
	    id: "ok",
	    name: "",
	    field: "ok",
	    width: 70,
	    cssClass: "cell-effort-driven",	    
	    cannotTriggerInsert: true,
	    formatter: Slick.Formatters.YesNo,
	    editor: Slick.Editors.Checkbox
	}];

	var options = {
			editable: true,
		    enableAddRow: true,
		    enableCellNavigation: true,
		    asyncEditorLoading: false,
		    rowHeight: 30
		};	
	
	grid = new Slick.Grid($("#myGrid"), data, columns, options);
	
	grid.onAddNewRow.subscribe(function (e, args) {
	// grid.onAddNewRow = function addItem(newItem,columnDef) {
		var item = {date:"", content:"", ok: true};
        
		item.date = current_date();
		
       $.extend(item, args.item);
       data.push(item);       
       grid.invalidateRows([data.length - 1]);
       grid.updateRowCount();
       grid.render();
    });
});
